home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
Xprof
/
xprof
/
message.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
5KB
|
174 lines
/*==================================================================
* File : message.c
* Package: Xprof
*
* Author : Aloke Gupta.
*
* (C) Copyright 1992, Aloke Gupta.
*==================================================================*/
/*
* 1. InitMsgStats (MsgStats *mstats, long timestamp, Detailed detailed,
* Grain size_grain)
* 2. FillMsgStats (Msgstats *mstats, long timestamp, long size,
long bytes)
* 3. PrintMsgStats (FILE *fp, MsgStats *mstats, char *message)
* 4. PrintMsgDetails(FILE *fp, MsgStats *mstats, char *message)
*/
#include <stdio.h>
#include <memory.h>
#include "common.h"
int MAXBUCKETS_SIZE=4096; /* Array size for size stats */
/* Initialize the MsgStats structure */
InitMsgStats(mstats, timestamp, detailed, size_grain)
MsgStats *mstats;
long timestamp;
Detailed detailed; /* Should we maintain detailed information ? */
Grain size_grain;
{
mstats->invoked = TRUE;
mstats->number = 0;
mstats->total_bytes = 0;
mstats->last_time = timestamp;
mstats->size_grain = size_grain;
if (detailed == DETAILED) {
mstats->detailed = DETAILED;
mstats->iat_distbn = (long *) calloc(MAXBUCKETS_IAT, sizeof(long));
mstats->max_iat = 0;
mstats->min_iat = MAXLONG;
mstats->size_distbn = (long *) calloc(MAXBUCKETS_SIZE, sizeof(long));
mstats->max_size = 0;
mstats->min_size = MAXLONG;
if ((mstats->iat_distbn == NULL) || (mstats->size_distbn ==NULL)) {
fprintf(stderr, "Error: Memory allocation failed\n");
exit(1);
}
}
}
/* FillMsgStats.
* The timestamp, bytes, and size parameters control the filling of various
* fields in the MsgStats structure. Pass a -1 in these to suppress this.
* timestamp: max_iat, min_iat, iat_distbn, last_time
* size: max_size, min_size, size_distbn
* bytes: number, total_bytes
*/
FillMsgStats(mstats, timestamp, size, bytes)
MsgStats *mstats;
long timestamp;
long size;
long bytes;
{
long bucket;
/*
if ((mstats->detailed == TERSE) && ((timestamp > 0) || (size > 0)) ){
fprintf(stderr,"Error: Attempt to Fill uninitialized structure !!\n");
return(1);
}
*/
/* Fill the interarrival time distribution */
if (mstats->detailed == DETAILED) {
if (timestamp >= 0) {
bucket = (timestamp - mstats->last_time) / (long) IAT_GRAIN;
if (bucket > mstats->max_iat)
mstats->max_iat = bucket;
if (bucket < mstats->min_iat)
mstats->min_iat = bucket;
/* Actual array is filled to a log2 scale */
if (bucket > 0)
bucket = (long ) mylog2(bucket);
if (MAXBUCKETS_IAT <= bucket)
bucket = MAXBUCKETS_IAT - 1;
mstats->iat_distbn[bucket] ++;
/* Update the timestamp */
mstats->last_time = timestamp;
}
/*
* Fill in the size distribution for the requests.
*/
if (size >= 0) {
bucket = size / (long) mstats->size_grain;
if (bucket > mstats->max_size)
mstats->max_size = bucket;
if (bucket < mstats->min_size)
mstats->min_size = bucket;
if (MAXBUCKETS_SIZE <= bucket)
bucket = MAXBUCKETS_SIZE - 1;
mstats->size_distbn[bucket] ++;
}
}
if (bytes >= 0) {
mstats->number ++;
mstats->total_bytes += bytes;
}
}
PrintMsgStats(fp, mstats, message)
FILE *fp;
MsgStats *mstats; /* Data structure to print out */
char *message; /* Header message */
{
fprintf(fp, "\n\t\t***** Statistics for %s *****\n", message);
if (mstats->invoked == FALSE) {
return;
}
if (mstats->number > 0)
if (mstats->detailed == DETAILED) {/* Detailed stats were maintained */
fprintf(fp,"Inter-arrival time distribution (ms):\n");
process_stats(fp,mstats->min_iat, mstats->max_iat, mstats->iat_distbn,
IAT_GRAIN, (long) MAXBUCKETS_IAT, LOG2);
fprintf(fp,"Size distribution:\n");
process_stats(fp,mstats->min_size,mstats->max_size, mstats->size_distbn,
mstats->size_grain, (long) MAXBUCKETS_SIZE, LINEAR);
}
}
PrintMsgDetails(fp, mstats, message)
FILE *fp;
MsgStats *mstats; /* Data structure to print out */
char *message; /* Header message */
{
long i;
if (mstats->invoked == FALSE) {
fprintf(fp,"Error: This structure has never been invoked\n");
exit(1);
}
fprintf(fp,"\n\t\t***** Raw Statistics for %s *****\n", message);
if (mstats->number > 0)
if (mstats->detailed == DETAILED) {/* Detailed stats were maintained */
fprintf(fp,"\tInter-arrival time distribution (ms):\n");
fprintf(fp,"%7s %10s\n","i", "freq");
for (i = 0; i < MAXBUCKETS_IAT; i++) {
if (mstats->iat_distbn[i] > 0)
fprintf(fp,"%7ld %10ld\n",(long) myexp2(i) * (long) IAT_GRAIN,
mstats->iat_distbn[i]);
}
fprintf(fp,"\tSize distribution:\n");
fprintf(fp,"%7s %10s\n","i", "freq");
for (i = 0; i < MAXBUCKETS_SIZE; i++) {
if (mstats->size_distbn[i] > 0)
fprintf(fp,"%7ld %10ld\n", (long) i * (long) mstats->size_grain,
mstats->size_distbn[i]);
}
}
}